// 导入路由组件
// import Home from '@/page/home/home.vue'
import Search from '@/page/search/search.vue'
import Login from '@/page/login/login.vue'
import Register from '@/page/register/register.vue'
import Detail from '@/page/detail/detail.vue'
import AddCartSuccess from '@/page/AddCartSuccess/addcartsuccess.vue'
import ShopCart from '@/page/ShopCart/shopcart.vue'
import Trade from "@/page/Trade/trade.vue"
import Pay from "@/page/Pay/pay.vue"
import PaySuccess from '@/page/PaySuccess/paysuccess.vue'
import Center from '@/page/Center/center.vue'
// 导入子路由
import MyOrder from '@/page/Center/myOrder/myorder.vue'
import GroupOrder from '@/page/Center/groupOrder/grouporder.vue'

// 路由懒加载
const Foo = () => {
  return import('@/page/home/home.vue')
}

export default [
  {
    path: '/home',
    // component: Foo,
    // 路由懒加载
    component: () => import('@/page/home/home.vue'),
    meta: { show: true, getnavlist: true }
  },
  {
    path: '/center',
    component: Center,
    meta: { show: true },
    children: [
      // 重定向
      {
        path: '/center',
        redirect: '/center/myorder'
      },
      {
        // 完整写法
        path: '/center/myorder',
        // path: 'myorder',
        component: MyOrder
      },
      {
        // 简写:不需要带 '/'
        path: 'grouporder',
        component: GroupOrder
      }
    ]
  },
  {
    path: '/paysuccess',
    component: PaySuccess,
    meta: { show: true }
  },
  {
    path: '/pay',
    component: Pay,
    meta: { show: true },
    // 路由独享守卫
    beforeEnter: (to, from, next) => {
      if (from.path == '/trade') {
        next()
      } else {
        // next(false) 等于从哪来回哪去,原地不动
        next(false)
        // console.log(to);
        // console.log(from);
      }
    }
  },
  {
    path: '/trade',
    component: Trade,
    meta: { show: true },
    // 路由独享守卫
    beforeEnter: (to, from, next) => {
      if (from.path == '/shopcart') {
        next()
      } else {
        // next(false) 等于从哪来回哪去,原地不动
        next(false)
      }
    }
  },
  {
    path: '/shopcart',
    component: ShopCart,
    meta: { show: true }
  },
  {
    name: 'search',
    // ? : 为 params传不传都可以
    // path: '/search/:key?',
    path: '/search/:keyword?',
    component: Search,
    // 路由元信息
    meta: { show: true, getnavlist: true },
    // 开启路由传参
    // props: true
  },
  {
    name: 'login',
    path: '/login',
    component: Login,
    meta: { show: false }

  },
  {
    path: '/register',
    component: Register,
    meta: { show: false }
  },
  {
    path: "/",
    redirect: "/home"
  },
  {
    name: "detail",
    path: '/detail/:detailId?',
    component: Detail,
    meta: { show: true }
  },
  {
    name: "addcartsuccess",
    path: '/addcartsuccess',
    component: AddCartSuccess,
    meta: { show: true }
  }
]